﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using PowerCreator.LMS.Common.Utils;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Web.Paper;
using PowerCreator.LMS.Web.Question;
using PowerCreator.LMS.Paper.Entiry;
using PowerCreator.LMS.Question.Entiry;
using PowerCreator.LMS.ViewQuery;


public partial class sysadmin_PaperManager_ProjectList : PowerCreator.LMS.Web.Base.BasePage
{
    ManagerPaper objManagerPaper = new ManagerPaper();
    ManagerQuestion objManagerQuestion = new ManagerQuestion();
    ViewQuery objViewQuery = new ViewQuery();
    const string SEARCH_TTRAINCLASS_TTRAINPROJECT = "select TrainproID,TrainproName,count(TrainclaID)as ClassCount from TTrainProject  left join TTrainClass  on TrainproID=FKTrainclaTrainproID where 1=1 {0}   group by TrainproID,TrainproName";



    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!GetRole(Role.AuditProject))
        //{
        //    Script.ShowAndHistory("您没有培训方案批阅的权限!", -1);
        //    return;
        //}
        if (!IsPostBack)
        {
            string search = GetSearch();
            BinderPager(search);
            BinderGV(search, 1);
            InitPage();

        }
    
    }
    protected override void InitPage()
    {
        lbl_InfoTitle.Text = GetLanageValueByKey("lab_ProjectClassUser_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_ProjectName.Text = GetLanageValueByKey("lab_ProjectList_ProjectName", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnSearch.Text = GetLanageValueByKey("btn_Search", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }
    private string GetSearch()
    {
        string search = string.Format("and TrainproName like '%{0}%'", txtProjectName.Text.Trim());
        string strSearch = string.Format(SEARCH_TTRAINCLASS_TTRAINPROJECT, search);
        return strSearch.ToString();
    }
    private void BinderPager(string search)
    {
        AspNetPager1.RecordCount = objViewQuery.Count(search);
        AspNetPager1.PageSize = LMSPageSize;
    }

    private void BinderGV(string search, int pageIndex)
    {
        DataTable dt = new DataTable();
        dt = objViewQuery.Query(search, LMSPageSize, pageIndex);
        gvProjectList.DataSource = dt;
        gvProjectList.DataBind();

        PreAspNetPager(AspNetPager1);
    }

    protected void gvProjectList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.ToLower() == "myquery")
        {
            string url = "ProjectClassUser.aspx?p=" + e.CommandArgument.ToString();
            Script.RedirectURL(url);
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPager(search);
        BinderGV(search, 1);
    }
    protected void gvProjectList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Cells[0].Text = GetLanageValueByKey("lab_ProjectList_ProjectName", PowerCreator.LMS.Language.LanagetItemType.Page);
            e.Row.Cells[1].Text = GetLanageValueByKey("msg_ProjectClassUser_ClassCount", PowerCreator.LMS.Language.LanagetItemType.Page);

            e.Row.Cells[2].Text = GetLanageValueByKey("btn_ManagerQuestion_Work", PowerCreator.LMS.Language.LanagetItemType.Page);
            //e.Row.Cells[3].Text = GetLanageValueByKey("msg_ProjectClassUser_SubmitTime", PowerCreator.LMS.Language.LanagetItemType.Page);
            //e.Row.Cells[4].Text = GetLanageValueByKey("lab_ManagerPaperInfo_PaperState", PowerCreator.LMS.Language.LanagetItemType.Page);
            //e.Row.Cells[5].Text = GetLanageValueByKey("lab_EditUserPaper_RealScore", PowerCreator.LMS.Language.LanagetItemType.Page);
            //e.Row.Cells[6].Text = GetLanageValueByKey("msg_PaperUserList_pingjuanshijian", PowerCreator.LMS.Language.LanagetItemType.Page);
            //e.Row.Cells[7].Text = GetLanageValueByKey("btn_ManagerQuestion_Work", PowerCreator.LMS.Language.LanagetItemType.Page);

            //e.Row.Cells[8].Text = GetLanageValueByKey("msg_PaperUserList_pingjuanren", PowerCreator.LMS.Language.LanagetItemType.Page);
            //e.Row.Cells[9].Text = GetLanageValueByKey("btn_ManagerQuestion_Work", PowerCreator.LMS.Language.LanagetItemType.Page);

        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("bgColor", "#F7FAFF");
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#FAEDB8'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#F7FAFF'");

            LinkButton ibtnQuery = (LinkButton)e.Row.Cells[2].FindControl("ibtnQuery");
            ibtnQuery.Text = GetLanageValueByKey("btn_PaperList_xiangqing", PowerCreator.LMS.Language.LanagetItemType.Page);
        } 
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderGV(search, AspNetPager1.CurrentPageIndex);
    }
}
